package caiwei.android_study_sample.service;

import android.app.Service;
import android.content.Intent;
import android.media.MediaPlayer;
import android.os.Binder;
import android.os.IBinder;
import android.util.Log;
import caiwei.android_study_sample.R;

public class Android06Myservice extends Service
{
	private MediaPlayer mMediaPlayer;
	private MyBinder mMyBinder=new MyBinder();
	@Override
	public IBinder onBind(Intent intent)
	{
		Log.i("Mylog", "bindsevice onBind");		
		return mMyBinder;
	}

	@Override
	public int onStartCommand(Intent intent, int flags, int startId)
	{
		Log.i("Mylog","service onStartCommand");
		mMediaPlayer=MediaPlayer.create(this, R.raw.yueliang);
		mMediaPlayer.start();
		return super.onStartCommand(intent, flags, startId);
	}

	@Override
	public void onCreate()
	{
		Log.i("Mylog", "startsevice onCreate");
		super.onCreate();
	}

	@Override
	public void onDestroy()
	{	
		mMediaPlayer.stop();
		Log.i("Mylog", "startsevice onDestroy");
		super.onDestroy();
	}

	@Override
	public boolean onUnbind(Intent intent)
	{
		Log.i("Mylog", "bindsevice onUnbind");
		return super.onUnbind(intent);
	}
	public class MyBinder extends Binder
	{
		public Android06Myservice getMyservice(){
			return Android06Myservice.this;			
		}
	}
	public void play()
	{
		System.out.println("=================================");
		mMediaPlayer=MediaPlayer.create(this, R.raw.yueliang);
		mMediaPlayer.start();
	}
}
